package com.iris.net;

import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class HttpTest {
	public String doGet(){
		return null;
	}

	public String doPost(){
		return null;
	}
	public String executeJSFun() throws ScriptException, NoSuchMethodException{
		  // 调用js。。 
		  ScriptEngineManager scriptManager = new ScriptEngineManager();
		  ScriptEngine js = scriptManager.getEngineByExtension("js");
		  // 执行JS
		  js.eval("function test(){$('#test').val('ddd');return '99';}");
		  Invocable inv = (Invocable) js;
		  // p1的获取 执行js中的方法
		  String p1 = (String) inv.invokeFunction("test");
		  System.out.println(p1);
		  return p1;
	}
	
	public static void main(String[] args) {
		HttpTest ht=new HttpTest();
		try {
			ht.executeJSFun();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (ScriptException e) {
			e.printStackTrace();
		}
	}
}
